import pygame
import os

# 初始化pygame
pygame.init()

def load_image(file):
    """loads an image, prepares it for play"""
    file = os.path.join(main_dir, "data", file)
    try:
        surface = pygame.image.load(file)
    except pygame.error:
        raise SystemExit(f'Could not load image "{file}" {pygame.get_error()}')
    return surface.convert()

def load_sound(file):
    """because pygame can be compiled without mixer."""
    if not pygame.mixer:
        return None
    file = os.path.join(main_dir, "data", file)
    try:
        sound = pygame.mixer.Sound(file)
        return sound
    except pygame.error:
        print(f"Warning, unable to load, {file}")
    return None

# 加载音频文件
file = "boom.wav"
# file = "car_door.wav"
file = "house_lo.wav"
main_dir = os.path.split(os.path.abspath(__file__))[0]
file = os.path.join(main_dir, "data", file)

sound = pygame.mixer.Sound(file)

# 播放音频文件
sound.play()


# 等待音频播放完成
while pygame.mixer.get_busy():
    pygame.time.delay(100)

# 退出pygame
pygame.quit()
